﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace CarHelpDesk.Web
{
    public static class ControllerExtensions
    {
        /// <summary>
        /// Extension method to Controller class
        /// Gets the GUID if the current authenticated user.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <returns>The guid of the the user</returns>
        /// <example>
        ///     AccountController controller = new AccountController();
        ///     controller.GetCurrentUserID();
        /// </example>
        public static Guid GetCurrentUserID(this Controller controller)
        {
            MembershipUser user = Membership.GetUser(controller.User.Identity.Name);
            
            return (Guid)user.ProviderUserKey;
        }
    }
}
